
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
  <meta charset="utf-8">
  <title>ksnowlv</title>
  <meta name="author" content="律威">

  
  <meta name="description" content="针对Objective-C-,Clang编译器内置哪些宏呢？
像平时看到的 __BLOCK__:是否支持block? __unsafe_unretained:LLVM 编译器 3.0版本之后,可以在不使用ARC下,可用. __weak:LLVM 编译器 3.0版本之后,可以在不使用ARC下,可用 &hellip;">
  

  <!-- http://t.co/dKP3o1e -->
  <meta name="HandheldFriendly" content="True">
  <meta name="MobileOptimized" content="320">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  
  <link rel="canonical" href="http://ksnowlv.github.io/blog/page/10">
  <link href="/favicon.png" rel="icon">
  <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
  <link href="/atom.xml" rel="alternate" title="ksnowlv" type="application/atom+xml">
  <script src="/javascripts/modernizr-2.0.js"></script>
  <script src="//ajax.useso.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  <script>!window.jQuery && document.write(unescape('%3Cscript src="./javascripts/lib/jquery.min.js"%3E%3C/script%3E'))</script>
  <script src="/javascripts/octopress.js" type="text/javascript"></script>
  <!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.useso.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.useso.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">

  
  <script type="text/javascript">
    var _gaq = _gaq || [];
     _gaq.push(['_setAccount', 'UA-39546615-2']);
    // _gaq.push(['_trackPageview']);

    // (function() {
    //   var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    //   ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    //   var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    // })();

    _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src='http://droidyue-tools.qiniudn.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
      })();
  </script>


</head>

<body   >
  <header role="banner"><hgroup>
  <h1><a href="/">ksnowlv</a></h1>
  
    <h2>回顾过去,总结以往;立足现在,铭记当下;技术为主,笔记而已.</h2>
  
</hgroup>

</header>
  <nav role="navigation"><ul class="subscription" data-subscription="rss">
  <li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
  
</ul>
  
<form action="http://google.com/search" method="get">
  <fieldset role="search">
    <input type="hidden" name="q" value="site:ksnowlv.github.io" />
    <input class="search" type="text" name="q" results="0" placeholder="Search"/>
  </fieldset>
</form>
  
<ul class="main-navigation">
  <li><a href="/">博客首页</a></li>
  <li><a href="/blog/archives">文章列表</a></li>
  <!-- <li><a href="/about-me">关于我</a></li>
 -->
</ul>

</nav>
  <div id="main">
    <div id="content">
      <div class="blog-index">
  
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/blog/2014/08/16/objective-c-clang-yu-bian-yi-hong/">Objective-C-Clang预编译宏</a></h1>
    
    
      <p class="meta">
        








  


<time datetime="2014-08-16T10:42:00+08:00" pubdate data-updated="true">Aug 16<span>th</span>, 2014</time>
        
         | <a href="/blog/2014/08/16/objective-c-clang-yu-bian-yi-hong/#disqus_thread">Comments</a>
        
      </p>
    
  </header>


  <div class="entry-content"><p>针对Objective-C-,<a href="http://zh.wikipedia.org/wiki/Clang">Clang</a>编译器内置哪些宏呢？
像平时看到的</p>

<p><code>__BLOCK__</code>:是否支持block?</p>

<p><code>__unsafe_unretained</code>:LLVM 编译器 3.0版本之后,可以在不使用ARC下,可用.</p>

<p><code>__weak</code>:LLVM 编译器 3.0版本之后,可以在不使用ARC下,可用.</p>

<p><code>__strong</code>:LLVM 编译器 3.0版本之后,可以在不使用ARC下,可用.</p>

<p><code>__block</code>:块变量。</p>

<p>等.</p>

<p>那Clang编译器支持的所有宏定义可通过</p>

<pre><code>clang -dM -E - &lt; /dev/null
</code></pre>

<p>命令查看
 </div>
  
  
    <footer>
      <a rel="full-article" href="/blog/2014/08/16/objective-c-clang-yu-bian-yi-hong/">阅读全文&rarr;</a>
    </footer>
  


    </article>
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/blog/2014/08/15/block-shi-yong-xian-zhi/">Block关键字使用限制</a></h1>
    
    
      <p class="meta">
        








  


<time datetime="2014-08-15T19:53:00+08:00" pubdate data-updated="true">Aug 15<span>th</span>, 2014</time>
        
         | <a href="/blog/2014/08/15/block-shi-yong-xian-zhi/#disqus_thread">Comments</a>
        
      </p>
    
  </header>


  <div class="entry-content"><p><strong>__block</strong>变量有两个限制</p>

<pre><code>1.不能是可变长度的数组。
2.不能是包含C99可变长度数组的结构体。
</code></pre>

<h4>1.可变数组</h4>

<h4>C99中的可变长数组（variable length array，简称VLA）</h4>

<pre><code>可变长指的是编译期可变，数组定义时,其长度可为整数类型的表达式.
</code></pre>

<h4>C99中的可变改类型（variably modified type，简称VM）。</h4>

<pre><code>一个含有源自VLA派生的完整声明器被称为可变改的。VM包含了VLA和指向VLA的指针;
注意VM类型并没有创建新的类型种类，VLA和指向VLA的指针仍然属于数组类型和指针类型，
是数组类型和指针类型的扩展
</code></pre>

<h4>总结:</h4>

<h4>VLA虽然定义时长度可变，但还不是动态数组，在运行期内不能再改变;</h4>

<p>代码示例:</p>

<p><img src="/images/post/2014-08-15-__block-shi-yong-xian-zhi/var_length_demo.png" alt="image" /></p>

<h4>而指针类型的数组是在运行期间确定下来的，而且在运行期间也是可以改变的。</h4>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
</pre></td><td class='code'><pre><code class='objective-c'><span class='line'>    <span class="n">__block</span> <span class="kt">char</span><span class="o">*</span> <span class="n">string</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
</span><span class='line'>    <span class="n">__block</span> <span class="n">size_t</span> <span class="n">stringLength</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'>    <span class="kt">void</span> <span class="p">(</span><span class="o">^</span><span class="n">showMessage</span><span class="p">)(</span><span class="n">NSString</span> <span class="o">*</span><span class="n">message</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'>    <span class="n">showMessage</span> <span class="o">=</span> <span class="o">^</span><span class="p">(</span><span class="n">NSString</span> <span class="o">*</span><span class="n">message</span><span class="p">)</span>
</span><span class='line'>    <span class="p">{</span>
</span><span class='line'>        <span class="kt">int</span> <span class="n">length</span> <span class="o">=</span> <span class="p">[</span><span class="n">message</span> <span class="nl">lengthOfBytesUsingEncoding:</span><span class="n">NSUTF8StringEncoding</span><span class="p">];</span>
</span><span class='line'>
</span><span class='line'>        <span class="n">stringLength</span> <span class="o">=</span> <span class="p">(</span><span class="n">length</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="k">sizeof</span><span class="p">(</span><span class="kt">char</span><span class="p">);</span>
</span><span class='line'>        <span class="n">string</span> <span class="o">=</span> <span class="n">calloc</span><span class="p">(</span><span class="n">stringLength</span><span class="p">,</span><span class="n">stringLength</span><span class="p">);</span>
</span><span class='line'>        <span class="n">memcpy</span><span class="p">(</span><span class="n">string</span><span class="p">,</span> <span class="p">[</span><span class="n">message</span> <span class="n">UTF8String</span><span class="p">],</span> <span class="n">stringLength</span><span class="p">);</span>
</span><span class='line'>        <span class="n">NSLog</span><span class="p">(</span><span class="s">@&quot;string = %s&quot;</span><span class="p">,</span><span class="n">string</span><span class="p">);</span>
</span><span class='line'>    <span class="p">};</span>
</span><span class='line'>
</span><span class='line'>    <span class="n">showMessage</span><span class="p">(</span><span class="s">@&quot;hello world&quot;</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'>    <span class="k">if</span> <span class="p">(</span><span class="n">string</span> <span class="o">&amp;&amp;</span> <span class="n">stringLength</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>
</span><span class='line'>        <span class="n">NSLog</span><span class="p">(</span><span class="s">@&quot;string = %s, string[0] = %c&quot;</span><span class="p">,</span><span class="n">string</span><span class="p">,</span><span class="n">string</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span>
</span><span class='line'>
</span><span class='line'>        <span class="n">free</span><span class="p">(</span><span class="n">string</span><span class="p">);</span>
</span><span class='line'>        <span class="n">string</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
</span><span class='line'>    <span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<h4>2.柔性数组结构成员</h4>

<pre><code> 1.结构中的最后一个元素允许是未知大小的数组，这就叫做柔性数组成员；
 2.结构中的柔性数组成员前面必须至少一个其他成员。
 柔性数组成员允许结构中包含一个大小可变的数组。
 sizeof返回的这种结构大小不包括柔性数组的内存。
 包含柔性数组成员的结构用malloc ()函数进行内存的动态分配。
</code></pre>

<h4>一种可变长度的结构 代码示例:</h4>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class='objective-c'><span class='line'><span class="cp">#声明一结构体</span>
</span><span class='line'><span class="k">typedef</span> <span class="k">struct</span> <span class="n">TStudent</span>
</span><span class='line'><span class="p">{</span>
</span><span class='line'>    <span class="kt">int</span> <span class="n">number</span><span class="p">;</span>
</span><span class='line'>    <span class="kt">char</span> <span class="n">name</span><span class="p">[];</span>
</span><span class='line'><span class="p">}</span><span class="n">StudentType</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'><span class="cp">#创建一结构体</span>
</span><span class='line'>
</span><span class='line'><span class="n">StudentType</span> <span class="o">*</span><span class="n">p</span> <span class="o">=</span> <span class="p">(</span><span class="n">StudentType</span> <span class="o">*</span><span class="p">)</span> <span class="n">malloc</span><span class="p">(</span> <span class="k">sizeof</span> <span class="p">(</span> <span class="n">StudentType</span> <span class="p">)</span><span class="o">+</span><span class="mi">10</span><span class="o">*</span><span class="k">sizeof</span><span class="p">(</span><span class="kt">char</span><span class="p">));</span>
</span></code></pre></td></tr></table></div></figure>



</div>
  
  


    </article>
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/blog/2014/08/15/xcode-other-link-flags-list/">Xcode-other-link-flags支持的参数</a></h1>
    
    
      <p class="meta">
        








  


<time datetime="2014-08-15T08:14:00+08:00" pubdate data-updated="true">Aug 15<span>th</span>, 2014</time>
        
         | <a href="/blog/2014/08/15/xcode-other-link-flags-list/#disqus_thread">Comments</a>
        
      </p>
    
  </header>


  <div class="entry-content"><h4>Xcode的&#8221;<code>other link flags</code>&ldquo;都支持哪些选项呢？可参考<a href="http://stackoverflow.com/questions/14497872/other-linker-flags-list">http://stackoverflow.com/questions/14497872/other-linker-flags-list</a>中提到的“ <code>man ld</code>”命令,在<code>Mac Terminal</code>下是有效的</h4>

<pre><code>ksnowlv@ksnowlvdeMacBook-Pro~$man ld
</code></pre>

<p><img src="/images/post/2014-08-15-xcode-other-link-flags-list/overview.png" alt="image" /></p>

<h4>我们常用<code>-ObjC</code>,<code>-all_load</code>,<code>-force_load</code></h4>

<p><img src="/images/post/2014-08-15-xcode-other-link-flags-list/other_link_flag.png" alt="image" /></p>
</div>
  
  


    </article>
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/blog/2014/08/14/selector-not-recognized-fix/">&#34;selector Not Recognized&#34;的crash原因及解决办法</a></h1>
    
    
      <p class="meta">
        








  


<time datetime="2014-08-14T19:17:00+08:00" pubdate data-updated="true">Aug 14<span>th</span>, 2014</time>
        
         | <a href="/blog/2014/08/14/selector-not-recognized-fix/#disqus_thread">Comments</a>
        
      </p>
    
  </header>


  <div class="entry-content"><h4>在iOS开发中,经常会遇见&#8221;selector not recognized&#8221;这种类型的crash,其原因:</h4>

<h4>1.该方法实际上不存在.</h4>

<pre><code>1.检查是否拼写错误。
2.检查该方法在iOS SDK版本中的适用版本范围。
3.检查对象传递是否传递有误。
</code></pre>

<h4>2.内存管理不当。</h4>

<pre><code>1.你的App试图引用一个已经被释放的对象.可以使用Zombies检查下问题原因。
2.检查是否有内存越界的问题,可以开启内存防护，日志等选项,再添加异常断点。
</code></pre>

<h4>内存防护，日志等选项开启</h4>

<p><img src="/images/post/2014-08-14-selector-not-recognized-fix/memory_option.png" alt="image" /></p>

<h4>异常断点开启</h4>

<p><img src="/images/post/2014-08-14-selector-not-recognized-fix/exceptions_breakpoint.png" alt="image" />;</p>

<h4>3.使用静态库分类方法加载不当。</h4>

<pre><code>静态库的分类方法默认是不加载的,-需要检查编译选项设置。
   -ObjC,-all_load,-force_load 
</code></pre>

<p>  详情见<a href="http://ksnowlv.github.io/blog/2014/08/12/xcode-zhi-forceload/">force_load等编译选项区别</a></p>
</div>
  
  


    </article>
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/blog/2014/08/13/si-gui/">思归</a></h1>
    
    
      <p class="meta">
        








  


<time datetime="2014-08-13T21:41:00+08:00" pubdate data-updated="true">Aug 13<span>th</span>, 2014</time>
        
         | <a href="/blog/2014/08/13/si-gui/#disqus_thread">Comments</a>
        
      </p>
    
  </header>


  <div class="entry-content"><p>不知不觉，来杭州已快半年了!</p>

<p>这半年，北京，杭州每月来回穿梭,总是人在路上，心在远方.</p>

<p>在杭州的日子里,工作,生活，学习三点一线之外,偶尔出外耍耍.</p>

<p>对杭州的印象,这边风景不错,生活是安逸,节奏慢些.</p>

<p>这种安逸,现在让我感觉那么美丽,恐怖!</p>

<pre><code>生于忧患,死于安乐!
</code></pre>

<p>当你觉得,太安逸了，太苦了,也是必须快速调整的时候了.</p>

<pre><code>人,总要有激情地活着，激情地梦着.....
</code></pre>

<p>这几天,一直在和leader沟通回北京的事情;现在,看起来，依然不可期.</p>

<p>我期望,在这十天内,会有好消息传来,可以回北京了;9月24日这个周末前.想到这里，我觉得,很是兴奋.</p>

<p>老婆意外的发现,我的Mac QQ上有个红色的皇冠,你瞧瞧:</p>

<p><img src="/images/post/2014-08-13-si-gui/qq_icon.jpg" alt="image" /></p>
</div>
  
  


    </article>
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/blog/2014/08/12/xcode-zhi-forceload/">Xcode之ObjC/all_load/force_load</a></h1>
    
    
      <p class="meta">
        








  


<time datetime="2014-08-12T23:51:00+08:00" pubdate data-updated="true">Aug 12<span>th</span>, 2014</time>
        
         | <a href="/blog/2014/08/12/xcode-zhi-forceload/#disqus_thread">Comments</a>
        
      </p>
    
  </header>


  <div class="entry-content"><h4>1.应用场景:</h4>

<pre><code>在项目中，可能会使用多个第三方的库。
如果使用-all_load选项，这会导致所有的类的方法都会被载入.
不管“你的程序”有没有用到，所有的，包括系统的，方法会被载入,
这不仅导致目标程序大小增大，而且容易引起一些冲突;
而这些冲突往往你无法解决(常常出现在你链接的各种库中）。
</code></pre>

<h4>2.如何解决这种问题呢？你可以使用-force_load.</h4>

<pre><code>指定要载入所有方法的库,但是仅在Xcode3.2之后才支持.
然后，在other linker flags 中配置-force_load（第一项为-force_load 第二项为.a路径）
</code></pre>

<h4>3.注意事项:</h4>

<pre><code>Xcode5之前的版本重启Xcode!!!（注意一定要重启）
Xcode5及以后的不需要重启Xcode
</code></pre>

<h4>4.最终设置:</h4>

<h4>静态库的设置</h4>

<p><img src="/images/post/2014-08-12-xcode-zhi-forceload/library_path.png" alt="image" /></p>

<h4><code>other linker flags</code>设置</h4>

<p><img src="/images/post/2014-08-12-xcode-zhi-forceload/other_link_flag.png" alt="image" /></p>

<h3>总结:</h3>

<h4>1. -ObjC与-force_load,-all_load的区别.</h4>

<pre><code>-ObjC加载所有类和有本类的分类，对于系统本类的分类是不加载的。
-force_load,-all_load,加载类所有的方法，包括系统本类的分类方法。  
</code></pre>

<h4>2.<code>-force-load</code>,<code>-all_load</code>,所做的事情是相同的,但是，是有区别的</h4>

<pre><code>-all_load是加载所有静态库中所有的类,分类,可能导致冲突。 
-force_load是指定加载某个静态库中所有的类,分类,不影响其它类按需加载。
</code></pre>
</div>
  
  


    </article>
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/blog/2014/08/11/dan-li-de-nei-cun-xie-lou/">单例的内存泄漏</a></h1>
    
    
      <p class="meta">
        








  


<time datetime="2014-08-11T22:35:00+08:00" pubdate data-updated="true">Aug 11<span>th</span>, 2014</time>
        
         | <a href="/blog/2014/08/11/dan-li-de-nei-cun-xie-lou/#disqus_thread">Comments</a>
        
      </p>
    
  </header>


  <div class="entry-content"><p>今天发现iOS上的单例，在苹果自带memory leak工具中,</p>

<pre><code>使用iOS6显示有内容泄漏。
使用iOS7或以上无内存泄漏。
</code></pre>

<p>推测应该是iOS系统对内存回收策略可能不太一样。</p>

<p>单例创建对象一次，会在App被退出时被系统回收,不用担心内存泄漏的。</p>

<pre><code>在iOS7或以上有内存泄漏时，检查下单例中创建某些对象时， 是不是忘记对原有对象回收?!
</code></pre>
</div>
  
  


    </article>
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/blog/2014/08/10/macxia-an-zhuang-django/">Mac下安装Django</a></h1>
    
    
      <p class="meta">
        








  


<time datetime="2014-08-10T20:05:00+08:00" pubdate data-updated="true">Aug 10<span>th</span>, 2014</time>
        
         | <a href="/blog/2014/08/10/macxia-an-zhuang-django/#disqus_thread">Comments</a>
        
      </p>
    
  </header>


  <div class="entry-content"><p>安装步骤如下</p>

<h4>1.Django安装前，先安装python,再安装pip</h4>

<pre><code>ksnowlv@ksnowlvdeMacBook-Pro~/Movies/python server$sudo easy_install pip
Password:
Searching for pip
Reading http://pypi.python.org/simple/pip/
Best match: pip 1.5.6
Downloading https://pypi.python.org/packages/source/p/pip/        pip-1.5.6.tar.gz#md5=01026f87978932060cc86c1dc527903e
Processing pip-1.5.6.tar.gz
Running pip-1.5.6/setup.py -q bdist_egg --dist-dir /tmp/easy_install-8B1wUW/pip-1.5.6/egg-dist-tmp-7Tfgxf
warning: no files found matching 'pip/cacert.pem'
warning: no files found matching '*.html' under directory 'docs'
warning: no previously-included files matching '*.rst' found under     directory 'docs/_build'
no previously-included directories found matching 'docs/_build/_sources'
Adding pip 1.5.6 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin

Installed /Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
ksnowlv@ksnowlvdeMacBook-Pro~/Movies/python server$
</code></pre>

<h4>2.然后安装Django：</h4>

<pre><code>ksnowlv@ksnowlvdeMacBook-Pro~/Movies/python server$sudo pip install Django
Password:
Downloading/unpacking Django
  Downloading Django-1.6.5-py2.py3-none-any.whl (6.7MB): 6.1MB downloaded
Cleaning up...
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py", line 122, in main
status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/commands/install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 1197, in prepare_files
do_download,
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/req.py", line 1375, in unpack_url
self.session,
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/download.py", line 572, in unpack_http_url
download_hash = _download_url(resp, link, temp_location)
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/download.py", line 433, in _download_url
for chunk in resp_read(4096):
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/download.py", line 421, in resp_read
chunk_size, decode_content=False):
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/_vendor/requests/packages/urllib3/response.py", line 240, in stream
data = self.read(amt=amt, decode_content=decode_content)
  File "/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg/pip/_vendor/requests/packages/urllib3/response.py", line 187, in read
data = self._fp.read(amt)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 567, in read
s = self.fp.read(amt)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 380, in read
data = self._sock.recv(left)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 241, in recv
return self.read(buflen)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 160, in read
return self._sslobj.read(len)
SSLError: The read operation timed out

Storing debug log for failure in /Users/ksnowlv/Library/Logs/pip.log
ksnowlv@ksnowlvdeMa
</code></pre>

<h4>3.安装出错，如何解决呢？方案是添加两个环境变量:</h4>

<pre><code>export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments
</code></pre>

<p>示例如下:</p>

<pre><code>ksnowlv@ksnowlvdeMacBook-Pro~/Movies/python server$export CFLAGS=-Qunused-arguments
ksnowlv@ksnowlvdeMacBook-Pro~/Movies/python server$export CPPFLAGS=-Qunused-arguments
ksnowlv@ksnowlvdeMacBook-Pro~/Movies/python server$sudo pip install Django
Password:
Downloading/unpacking Django
  Downloading Django-1.6.5-py2.py3-none-any.whl (6.7MB): 6.7MB downloaded
Installing collected packages: Django
Successfully installed Django
Cleaning up...
ksnowlv@ksnowlvdeMacBook-Pro~/Movies/python server$  
</code></pre>

<p><code>这个过程好折腾，找半天解决方案。希望大家多注意!!!</code></p>

<h4>4.验证下是否安装成功</h4>

<pre><code>ksnowlv@ksnowlvdeMacBook-Pro~/Movies/python server$python
Python 2.7.5 (default, Mar  9 2014, 22:15:05) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import django
&gt;&gt;&gt; print django.get_version()
1.6.5
#输出1.6.5 表示当前最新版本为1.6.5，表示已经安装成功
&gt;&gt;&gt; ^D
#退出python control + D
ksnowlv@ksnowlvdeMacBook-Pro~/Movies/python server$  
</code></pre>

<p>终于安装成功,大功告成!</p>
</div>
  
  


    </article>
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/blog/2014/08/10/python-wsgi-da-jian-web-server/">python-WSGI搭建web-server</a></h1>
    
    
      <p class="meta">
        








  


<time datetime="2014-08-10T16:43:00+08:00" pubdate data-updated="true">Aug 10<span>th</span>, 2014</time>
        
         | <a href="/blog/2014/08/10/python-wsgi-da-jian-web-server/#disqus_thread">Comments</a>
        
      </p>
    
  </header>


  <div class="entry-content"><h4>python提供了WSGI:Web Server Gateway Interface 只要求Web开发者实现一个函数即可响应HTTP请求。</h4>

<h4>application()函数必须由WSGI服务器来调用</h4>

<h4>先定义hello.py文件。</h4>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="c">#hello.py</span>
</span><span class='line'><span class="k">def</span> <span class="nf">application</span><span class="p">(</span><span class="n">environ</span><span class="p">,</span> <span class="n">start_response</span><span class="p">):</span>
</span><span class='line'>
</span><span class='line'><span class="n">start_response</span><span class="p">(</span><span class="s">&#39;200 OK&#39;</span><span class="p">,</span> <span class="p">[(</span><span class="s">&#39;Content-Type&#39;</span><span class="p">,</span> <span class="s">&#39;text/html&#39;</span><span class="p">)])</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">return</span> <span class="s">&#39;&lt;h1&gt;Hello, </span><span class="si">%s</span><span class="s">!&lt;/h1&gt;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">environ</span><span class="p">[</span><span class="s">&#39;PATH_INFO&#39;</span><span class="p">][</span><span class="mi">1</span><span class="p">:]</span> <span class="ow">or</span> <span class="s">&#39;web&#39;</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>


<h4>可以从<code>environ</code>里读取<code>PATH_INFO</code>，默认为web.</h4>

<h4>你可以在地址栏输入文本作为URL的一部分，将返回Hello, [输入文本]!</h4>

<h4>定义python_http_server.py文件，代码如下:</h4>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="c"># python_http_server.py</span>
</span><span class='line'><span class="c"># 从wsgiref模块导入:</span>
</span><span class='line'><span class="kn">from</span> <span class="nn">wsgiref.simple_server</span> <span class="kn">import</span> <span class="n">make_server</span>
</span><span class='line'><span class="c"># 导入我们自己编写的application函数:</span>
</span><span class='line'><span class="kn">from</span> <span class="nn">hello</span> <span class="kn">import</span> <span class="n">application</span>
</span><span class='line'>
</span><span class='line'><span class="c"># 创建一个服务器，IP地址为空，端口是8000，处理函数是application:</span>
</span><span class='line'><span class="n">httpd</span> <span class="o">=</span> <span class="n">make_server</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span> <span class="mi">8000</span><span class="p">,</span> <span class="n">application</span><span class="p">)</span>
</span><span class='line'><span class="k">print</span> <span class="s">&quot;Serving HTTP on port 8000...&quot;</span>
</span><span class='line'><span class="c"># 开始监听HTTP请求:</span>
</span><span class='line'><span class="n">httpd</span><span class="o">.</span><span class="n">serve_forever</span><span class="p">()</span>
</span></code></pre></td></tr></table></div></figure>


<h4>运行python_http_server.py</h4>

<pre><code>ksnowlv@ksnowlvdeMacBook-Pro~/Movies/python server$python python_http_server.py 
Serving HTTP on port 8000...
127.0.0.1 - - [10/Aug/2014 16:32:03] "GET / HTTP/1.1" 200 20
127.0.0.1 - - [10/Aug/2014 16:33:00] "GET /ksnowlv HTTP/1.1" 200 24
127.0.0.1 - - [10/Aug/2014 17:02:40] "GET /kair HTTP/1.1" 200 21
</code></pre>

<h4>注意：如果8000端口已被其他程序占用，启动将失败，请修改成其他端口。</h4>

<p>启动python server成功后，打开浏览器，输入<code>http://localhost:8000/</code>,输入ksnowlv,kair可以看到相关变化.</p>

<p><img src="/images/post/2014-08-10-python-wsgi-da-jian-web-server/web_server_result.png" alt="image" /></p>

<pre><code>hello.py和python_http_server.py放到同一个目录
</code></pre>
</div>
  
  


    </article>
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/blog/2014/08/09/mo-nu-a-jia-lu-you-ling/">魔女阿嘉璐-幽灵</a></h1>
    
    
      <p class="meta">
        








  


<time datetime="2014-08-09T17:07:00+08:00" pubdate data-updated="true">Aug 9<span>th</span>, 2014</time>
        
         | <a href="/blog/2014/08/09/mo-nu-a-jia-lu-you-ling/#disqus_thread">Comments</a>
        
      </p>
    
  </header>


  <div class="entry-content"><pre><code>DNF第二季70版本诺斯玛尔地区“疑惑之村”的美女领主魔女阿嘉璐,
在英雄级或领主之塔经常会施放一王牌必杀技-幽灵。
随机复制召唤出一个和该玩家一模一样的怪物对付玩家，伤害可观。
本人数次也惨死在自己幽灵的手里!
</code></pre>

<h4>天灾？人祸？这些总有人是躲不过的。</h4>

<h4>即使我们许多人比较幸运，安度一生。</h4>

<h4>人人都躲不过的，也许，就是自身的幽灵。</h4>

<h4>生活，工作，学习，太安逸了,必是必须图变求强的时刻</h4>

<h4>游戏里，你可以死于阿嘉璐的幽灵必杀技。</h4>

<h4>生活里，你需要时刻与幽灵长袖共舞。</h4>

<h4>&mdash;你没有重来一次的机会!</h4>

<p><code>今时今日的互联网行业，看起来比去年有些生机!!!</code></p>
</div>
  
  


    </article>
  
  <div class="pagination">
    
      <a class="prev" href="/blog/page/11/">&larr; Older</a>
    
    <a href="/blog/archives">Blog Archives</a>
    
    <a class="next" href="/blog/page/9/">Newer &rarr;</a>
    
  </div>
</div>
<aside class="sidebar">
  
    <section>
  <h1>关于我</h1>
  <p>律威,QQ:309235009 微信:ksnowlv</p>
  <p>手机单机游戏/手机网游封神online/手机阅读/腾讯iOS地图客户端&实时公交&开放API(地图&街景)/iPad/iPhone淘宝客户端及性能优化</p>
  <p>目前在银客做银客/简理财/&#8230;</p>
  <p>能做一点,是一点;不求大成,不求一万年;积少成多,水到渠成!</p>
</section>
<section>
  <h1>最近发布</h1>
  <ul id="recent_posts">
    
      <li class="post">
        <a href="/blog/2017/04/26/android-drawable/">Android drawable</a>
      </li>
    
      <li class="post">
        <a href="/blog/2017/04/22/iOS-xia-shi-yong-ffmpeg/">iOS下使用ffmpeg</a>
      </li>
    
      <li class="post">
        <a href="/blog/2015/08/19/ios-you-xian-hou-tai-ren-wu/">iOS有限后台任务</a>
      </li>
    
      <li class="post">
        <a href="/blog/2015/08/19/android-xia-jie-ya-suo/">Android下gzip数据流解压缩</a>
      </li>
    
      <li class="post">
        <a href="/blog/2015/08/19/facebook-infer-de-shi-yong/">FaceBook-infer的使用</a>
      </li>
    
  </ul>
</section>
<section>
  <h1>分类</h1>
    <ul id="category-list"><li><a href='/blog/categories/android-jie-ya-suo/'>Android-解压缩 (1)</a></li><li><a href='/blog/categories/androidduo-xian-cheng/'>Android多线程 (3)</a></li><li><a href='/blog/categories/androidcha-jian/'>Android插件 (1)</a></li><li><a href='/blog/categories/androidhui-tu-./'>Android绘图。 (1)</a></li><li><a href='/blog/categories/androidwang-luo/'>Android网络 (1)</a></li><li><a href='/blog/categories/git/'>git (6)</a></li><li><a href='/blog/categories/githubbo-ke/'>github博客 (8)</a></li><li><a href='/blog/categories/ios/'>iOS (6)</a></li><li><a href='/blog/categories/ios-block/'>iOS-block (1)</a></li><li><a href='/blog/categories/ios-bug/'>iOS-Bug (2)</a></li><li><a href='/blog/categories/ios-memory/'>iOS-Memory (4)</a></li><li><a href='/blog/categories/ios-push/'>iOS-push (1)</a></li><li><a href='/blog/categories/ios-ui/'>iOS-UI (2)</a></li><li><a href='/blog/categories/ios-you-hua/'>iOS-优化 (1)</a></li><li><a href='/blog/categories/ios-nei-cun/'>iOS-内存 (1)</a></li><li><a href='/blog/categories/ios-ji-chu/'>iOS-基础 (3)</a></li><li><a href='/blog/categories/ios-duo-xian-cheng/'>iOS-多线程 (3)</a></li><li><a href='/blog/categories/ios-cun-chu/'>iOS-存储 (1)</a></li><li><a href='/blog/categories/ios-an-quan/'>iOS-安全 (1)</a></li><li><a href='/blog/categories/ios-wang-luo/'>iOS-网络 (13)</a></li><li><a href='/blog/categories/ios-jie-ya-suo/'>iOS-解压缩 (1)</a></li><li><a href='/blog/categories/ios-she-ji-mo-shi/'>iOS-设计模式 (1)</a></li><li><a href='/blog/categories/ios-diao-shi/'>iOS-调试 (1)</a></li><li><a href='/blog/categories/iosyou-hua/'>iOS优化 (1)</a></li><li><a href='/blog/categories/iosji-chu/'>iOS基础 (2)</a></li><li><a href='/blog/categories/iosyin-pin/'>iOS音频 (1)</a></li><li><a href='/blog/categories/mac/'>Mac (4)</a></li><li><a href='/blog/categories/mac-duo-xian-cheng/'>Mac-多线程 (1)</a></li><li><a href='/blog/categories/nginx/'>nginx (3)</a></li><li><a href='/blog/categories/php/'>php (3)</a></li><li><a href='/blog/categories/python/'>python (12)</a></li><li><a href='/blog/categories/swift/'>swift (11)</a></li><li><a href='/blog/categories/uml/'>UML (8)</a></li><li><a href='/blog/categories/xcode/'>Xcode (11)</a></li><li><a href='/blog/categories/chan-pin-she-ji/'>产品设计 (2)</a></li><li><a href='/blog/categories/gong-ju/'>工具 (2)</a></li><li><a href='/blog/categories/shu-ju-ku/'>数据库 (2)</a></li><li><a href='/blog/categories/sheng-huo-pian-duan/'>生活片段 (10)</a></li><li><a href='/blog/categories/zhi-ye-sheng-ya/'>职业生涯 (7)</a></li><li><a href='/blog/categories/du-shu/'>读书 (2)</a></li></ul>
</section>
<section>
  <h1>外部链接</h1>
    <ul id="外部链接">
    	<li><a href="https://developer.apple.com">苹果开发者中心</a> </li>
    	<li><a href="http://stackoverflow.com/questions/tagged/ios">stackoverflow</a></li>
    	<li><a href="http://ksnowlv.blog.163.com/blog/#m=0">ksnowlv网易博客</a></li>
	</ul>
</section>

  
</aside>

    </div>
  </div>
  <footer role="contentinfo"><p>
  Copyright &copy; 2017 - 律威 -
  <span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>

  <script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1253538110'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "v1.cnzz.com/z_stat.php%3Fid%3D1253538110%26online%3D1' type='text/javascript'%3E%3C/script%3E"));</script>

  <script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F4c1727a94ea20751730e8a556dbdbf82' type='text/javascript'%3E%3C/script%3E"));
</script>

</p>



</footer>
  

<script type="text/javascript">
      var disqus_shortname = 'ksnowlv';
      
        
        var disqus_script = 'count.js';
      
    (function () {
      var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
      dsq.src = 'http://' + disqus_shortname + '.disqus.com/' + disqus_script;
      (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    }());
</script>








</body>
</html>
